import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import LoadData from '@/components/LoadData'
import Tab from '@/components/Tab'
import Product from '@/components/tabPages/Product'
import SelectPerson from '@/components/tabPages/SelectPerson'
import Supply from '@/components/tabPages/Supply'
import Interaction from '@/components/tabPages/Interaction'
import utils from '../config/utils'

Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/loadData',
      name: 'LoadData',
      component: LoadData
    },
    {
      path: 'tab',
      name: 'Tab',
      component: Tab,
      children: [
        {
          path: '/product',
          name: 'Product',
          component: Product
        },
        {
          path: '/selectPerson',
          name: 'SelectPerson',
          component: SelectPerson
        },
        {
          path: '/supply/:tid',
          name: 'Supply',
          component: Supply
        },
        {
          path: '/interaction',
          name: 'Interaction',
          component: Interaction
        }
      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  if(to.path != "/loadData"){
    sessionStorage["beforeLoginUrl"] = to.path
    var loadDone = utils.getData("loadDone");
    if(!loadDone) {
      next('/loadData')
      // window.location.href = "/#/wxAuth?code=123";
      return false
    }
  }
  next();
})
export default router
